package com.emser.unc.activitys;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

import com.emser.unc.R;
import com.emser.unc.activitys.resources.SaleReportSentAdapter;
import com.emser.unc.database.dao.SaleReportDataSource;
import com.emser.unc.serializable.SaleReportDTO;

public class SaleSummaryActivity extends ListActivity{
	

	private EditText toFind;
//	private Menu menu;
	private SaleReportDataSource datasource;
	private List<SaleReportDTO> reports;

	static final ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();

	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.m_sale_summary);
        initWidgets();
        initDatasource();

    }
    
    private void initWidgets() {
    	toFind = (EditText) findViewById(R.id.editTextProduct);
    	toFind.requestFocus();
    }
    
    private void initDatasource() {
    	datasource = new SaleReportDataSource(this);
		datasource.open();
		reports = datasource.getAllSentReports();
		SaleReportSentAdapter adapter = new SaleReportSentAdapter(SaleSummaryActivity.this,
				android.R.layout.simple_list_item_1, reports);
		setListAdapter(adapter);
		this.registerForContextMenu(this.getListView());
    }
    
    @Override
	protected void onResume() {
    	datasource.open();
    	super.onResume();
    }
    
    @Override
	protected void onPause() {
    	datasource.close();
    	super.onPause();
    }
    
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		Toast.makeText(this, "Selection ", Toast.LENGTH_LONG).show();
	}
    
//	@Override
//	public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
//		super.onCreateContextMenu(menu, v, menuInfo);
//	    MenuInflater inflater = getMenuInflater();
//	    inflater.inflate(R.menu.product_context_menu, menu);
//	}
    
//    @Override
//    public boolean onContextItemSelected(MenuItem item) {
//      int menuItemIndex = item.getItemId();
//      switch( menuItemIndex ) {
//      case R.id.item_detail:
//    	  Toast.makeText(this, "Ver Detalle del Item", Toast.LENGTH_LONG).show();
//    	  break;
//      default:
//    	  break;
//      }
//      return true;
//    }
    
//    @Override
//    public boolean onCreateOptionsMenu(Menu menu) {
//        MenuInflater inflater = getMenuInflater();
//        inflater.inflate(R.menu.product_menu, menu);
//        this.menu = menu;
//        this.menu.getItem(1).setTitle("Salir");
//        return true;
//    }
    
//    @Override
//    public boolean onOptionsItemSelected(MenuItem item) {
//        switch (item.getItemId()) {
//            case R.id.alphanumeric:
//                onAlphanumeric();
//                return true;
//            case R.id.cancel:
//                onCancel();
//                return true;                
//            default:
//                return super.onOptionsItemSelected(item);
//        }
//    }
    
}
